using UnityEngine;
using Unity.VisualScripting;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    [UnitShortTitle("Warning")]
    [UnitSurtitle("Log")]
    [UnitCategory("Unity Game Framework/Debugger")]
    public class LogWarningUnit : Unit
    {
        [DoNotSerialize] 
        [PortLabelHidden]
        public ControlInput Input { get; private set; }
        
        [PortLabelHidden]
        [DoNotSerialize]
        public ControlOutput Output { get; private set; }

        [PortLabelHidden]
        [DoNotSerialize]
        public ValueInput Value { get; private set; }
        
        [PortLabelHidden]
        [DoNotSerialize]
        public ValueOutput ValueOut { get; private set; }
        protected override void Definition()
        {
            Input = ControlInput(nameof(Input), In);
            Output = ControlOutput(nameof(Output));
            Value = ValueInput<object>(nameof(Value));
            ValueOut = ValueOutput<object>(nameof(ValueOut));
            Requirement(Value, Input);
            Succession(Input, Output);
        }
        
        private ControlOutput In(Flow flow)
        {
            var value = flow.GetValue<object>(Value);
            flow.SetValue(ValueOut, value);
            Log.Warning(value.ToString());
            return Output;
        }
    }
}